<!--管理员授课管理页面-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="org.edu.system.DBConnect" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta charset="UTF-8">
<title>课程管理</title>
<style type="text/css">
    th{
        text-align:center;/** 设置水平方向居中 */
        vertical-align:middle/** 设置垂直方向居中 */
    }
</style>
</head>
<body>
<br>
<form action="<%=request.getContextPath()%>/adm_course_info.jsp" method="post">
<button type="button" class="btn btn-primary btn-sm" onclick="window.location.href='./add_course.jsp'">添加课程</button>
<span style="float:right">查询课程：<input type="text" name="query" autocomplete="off"/>&nbsp;&nbsp;<input type="submit" class="btn btn-primary btn-sm" vluae="查询"/></span>
</form>
<center>
	<table border="1" style="text-align:center" width="100%" class="table table-striped table-bordered">
	<tr>
		<th>课程编号</th>
		<th>课程名称</th>
		<th>课程简介</th>
		<th colspan="2">记录操作</th>
	</tr>
	<%
		request.setCharacterEncoding("utf-8");
		Connection con = DBConnect.getCon();
		Statement stmt = null;
		ResultSet rs = null;
		stmt = con.createStatement();
		if(request.getParameter("query") != null)
		{
			System.out.print("查询成功！");
			String sql = "select * from course where course_id='"+request.getParameter("query")+"' or course_name='"+request.getParameter("query")+"'";
			rs = stmt.executeQuery(sql);//执行命令
			out.print("<br>");
			while (rs.next())
			{
				out.print("<tr height=\"50px\">");
				out.print("<td>"+rs.getString("course_id")+"</td>");
				out.print("<td>"+rs.getString("course_name")+"</td>");
				out.print("<td>"+rs.getString("course_info")+"</td>");
				out.print("<td><button class=\"btn btn-primary btn-xs\" onclick=\"javawwscript:if(confirm('确认修改该记录？')){location='./updateCourse.jsp?course_id="+rs.getString("course_id")+"'}\">修改课程</button></td><br>");
				out.print("<td><button class=\"btn btn-danger btn-xs\" onclick=\"javawwscript:if(confirm('确认删除该记录？')){location='./deleteCourse?course_id="+rs.getString("course_id")+"'}\">删除课程</button></td>");
				out.print("</tr>");
			} 
		}else
		{
			System.out.print("输出所有课程");
			String sql = "select * from course";
			rs = stmt.executeQuery(sql);//执行命令
			while (rs.next())
			{
				out.print("<tr height=\"50px\">");
				out.print("<td>"+rs.getString("course_id")+"</td>");
				out.print("<td>"+rs.getString("course_name")+"</td>");
				out.print("<td>"+rs.getString("course_info")+"</td>");
				out.print("<td><button class=\"btn btn-primary btn-xs\" onclick=\"javawwscript:if(confirm('确认修改该记录？')){location='./updateCourse.jsp?course_id="+rs.getString("course_id")+"'}\">修改课程</button></td><br>");
				out.print("<td><button class=\"btn btn-danger btn-xs\" onclick=\"javawwscript:if(confirm('确认删除该记录？')){location='./deleteCourse?course_id="+rs.getString("course_id")+"'}\">删除课程</button></td>");
				out.print("</tr>");
			} 
		}
	%>
	</table>
</center>
</body>
</html>